MIC=

SCHEDULER_INSTALL_PATH=${DAG_HOME}#/dag_task_scheduler
DEBUG = -DCHECK
OPT = -O3 #-g -O0 -std=gnu99

UPCC=upcc #-vv
UPC_FLAGS= -T=1 --uses-threads -O -opt #-save-temps

CXX = g++#icc 
CC = g++#icpc 
FC = gfortran#ifort 
#LIBFLAGS =  -L${SCHEDULER_INSTALL_PATH}/lib -ldag_task_scheduler -lpthread -lstdc++ -ltbb -lrt -L${HWLOC_HOME}/lib -lhwloc -lm #-L${LIBSCOTCH} -lscotch -lscotcherr -lm
LIBFLAGS =  -L${SCHEDULER_INSTALL_PATH}/lib -ldag_task_scheduler -lpthread -lstdc++ -ltbb -lrt -lm #-L${LIBSCOTCH} -lscotch -lscotcherr -lm

ifeq ($(MIC),TRUE)
CXX = icc -mmic
CC = icpc -mmic
FC = ifort -mmic
LIBFLAGS= -L/opt/intel/tbb42/lib/mic/ -L/opt/mpss/3.1.2/sysroots/k1om-mpss-linux/lib64/ -L/opt/mpss/3.1.2/sysroots/k1om-mpss-linux/lib64/ -L${SCHEDULER_INSTALL_PATH}/lib -ldag_task_scheduler -lpthread -ltbb  -lrt
endif

ifeq ($(MIC),TRUE)
EXTRA_FLAGS= -DSIZEX=512 -DSIZEY=512 -DSIZEZ=128
else
EXTRA_FLAGS= -DSIZEX=258 -DSIZEY=258 -DSIZEZ=130 
EXTRA_FLAGS+= -DINIT_SERIAL #-DINIT_CYCLIC  #-DGRAPH_REUSE -DGRAPH_DIST=10
#EXTRA_FLAGS+= -DSWEEP
#EXTRA_FLAGS+= -DINIT_BLOCKED #-DINIT_CYCLIC  #-DGRAPH_REUSE -DGRAPH_DIST=10
endif
CFLAGS = $(DEBUG) $(OPT) $(EXTRA_FLAGS) -Wall -I${SCHEDULER_INSTALL_PATH}/include 

EXTRA_FFLAGS= $(UPC_FLAGS) -DBLKX=32 -DBLKY=16 -DITER=5
FFLAGS = $(DEBUG) $(OPT) $(EXTRA_FFLAGS) -cpp -free -I${SCHEDULER_INSTALL_PATH}/include 
 
all:dag omp nest_weak
dag:
	$(CC) $(CFLAGS) -o 3d7p_dag 3d7p_dag.c $(LIBFLAGS)
multi_dag:
	$(CC) $(CFLAGS) -o 3d7p_dag_with_multi 3d7p_dag_with_multi.c $(LIBFLAGS)
nest_weak:
	$(CC) $(CFLAGS) -o 3d7p_dag_nest_weak 3d7p_dag_weak_dep.c $(LIBFLAGS)
multi_nest:
	$(CC) $(CFLAGS) -o 3d7p_dag_nest_weak_multi 3d7p_dag_weak_dep_with_multi.c $(LIBFLAGS)
fdag:
	$(FC) $(FFLAGS) -o 3d7p_dag 3d7p_dag.f timers.f $(LIBFLAGS) -lstdc++
upch:  3d7p_dag.o
	$(UPCC) $(UPC_FLAGS) $(DEBUG) -o 3d7p_upch 3d7p_dag.o $(LIBFLAGS) -lstdc++ 
3d7p_dag.o:  3d7p_dag.c
	$(UPCC) -c $(UPC_FLAGS) $(DEBUG)  $(EXTRA_FLAGS) -I${DAG_HOME}/include -o 3d7p_dag.o 3d7p_dag.c 
omp: 
	$(CXX) $(DEBUG) $(OPT) $(EXTRA_FLAGS) -Wall -fopenmp -o 3d7p_omp 3d7p_omp.cpp

clean:
	@-rm -f *.o
	@-rm -f 3d7p_dag 3d7p_omp *upch 3d7p_dag_nest_weak 3d7p_dag_nest_weak_multi
	@-rm -f *mod *csv *jpg *png loop_de* 
